package cn.com.fuhuitong.main.home.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import cn.com.fuhuitong.app.BaseApplication
import cn.com.fuhuitong.base.BaseViewModel
import cn.com.fuhuitong.http.HttpResponse
import cn.com.fuhuitong.http.ViewModelSubscribeListener
import cn.com.fuhuitong.main.home.entity.CategoryTwoResponse
import cn.com.fuhuitong.main.home.entity.FlagshipListResponse
import cn.com.fuhuitong.main.home.mode.HomeManager
import cn.com.fuhuitong.main.host.entity.ConfigResponse
import io.reactivex.disposables.Disposable

class FlagshipViewModel(application: Application) : BaseViewModel(application) {
    private val homeManager: HomeManager = HomeManager()

    val flagshipListDataLiveData = MutableLiveData<HttpResponse<FlagshipListResponse>>()

    val configDataLiveData = MutableLiveData<HttpResponse<ConfigResponse>>()


    private var page: Int = 1
    private var limit: Int = 100

    /**
     * 获取门店列表
     */
    fun flagshipIndex(search: String = "", lat: String, lng: String) {
        val listener =
            object : ViewModelSubscribeListener<FlagshipListResponse>(flagshipListDataLiveData) {}
        val flagshipIndexDisposable: Disposable = homeManager.flagshipIndex(
            search, lat, lng, page.toString(), limit.toString(), listener
        )
        dispose.add(flagshipIndexDisposable)
    }

    /**
     * 获取配置信息
     * */
    fun configValue(name: Array<String>) {
        val listener =
            object : ViewModelSubscribeListener<ConfigResponse>(configDataLiveData) {}
        val configValueDisposable: Disposable = homeManager.configValue(name, listener)
        dispose.add(configValueDisposable)
    }

    val categoryTwoLiveData = MutableLiveData<HttpResponse<CategoryTwoResponse>>()
    fun indexGetTwoHomeGoods(id: Int) {
        val listener =
            object : ViewModelSubscribeListener<CategoryTwoResponse>(categoryTwoLiveData) {}
        val caseIndexDisposable: Disposable = homeManager.indexGetTwoHomeGoods(
            BaseApplication.userToken(), id.toString(), listener
        )
        dispose.add(caseIndexDisposable)
    }
}